package com.xiaoxu.rental.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.xiaoxu.rental.entity.RentalType;
import com.xiaoxu.rental.mapper.RentalTypeMapper;
import com.xiaoxu.rental.service.RentalTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @author xtq
 * @description 针对表【busi_rental_type】的数据库操作Service实现
 * @createDate 2024-07-26 08:47:27
 */
@Service
@Transactional
public class RentalTypeServiceImpl extends ServiceImpl<RentalTypeMapper, RentalType>
        implements RentalTypeService {

    @Override
    public Page<RentalType> searchByPage(Page<RentalType> page, RentalType rentalType) {
        QueryWrapper<RentalType> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StrUtil.isNotEmpty(rentalType.getTypeName()), "type_name", rentalType.getTypeName());
        queryWrapper.le(ObjectUtils.isNotEmpty(rentalType.getHighDiscount()), "type_discount", rentalType.getHighDiscount());
        queryWrapper.ge(ObjectUtils.isNotEmpty(rentalType.getLowDiscount()), "type_discount", rentalType.getLowDiscount());
        return baseMapper.selectPage(page, queryWrapper);
    }

    @Override
    public boolean delete(String ids) {
        List<Integer> list =
                Arrays.stream(ids.split(",")).map(Integer::parseInt).toList();
        if (!list.isEmpty()) {
            return baseMapper.deleteBatchIds(list) > 0;
        }
        return false;
    }
}





